
// 1.\[  匹配 左右两个[]，必须用转义 
// 2.用（）做分组
// 3.\d 匹配数字，{2}代表匹配两位 {2,3}表示可以匹配两位也可也匹配三位
const parseExp = /\[(\d{2}):(\d{2})\.(\d{2,3})\]/

export function parseLyric(lyricString){
  const lineStrings = lyricString.split("\n")

  const lyrics = []
  for(let line of lineStrings){
    if(line){ //处理最后一行
      const result = parseExp.exec(line)
      if(!result) continue;
      const time1 = result[1] *60*1000
      const time2 = result[2] *1000
      const time3 = result[3].length === 3 ? result[3]*1 :result[3]*10
      const time =time1+time2+time3
      // console.log(time)
      const content = line.replace(parseExp,"").trim()
      const lineObj = {time, content}
      // console.log(lineObj)
      lyrics.push(lineObj)
    }
  }
  return lyrics
}